import { getIntl, request } from "@umijs/max";
import { message } from "antd";



export async function createPayment(data?: { [key: string]: any }) {
    return request('/admin-api/admin/payment/create', {
        method: 'POST',
        data: data
    });
}

export async function updatePayment(data?: { [key: string]: any }) {
    return request('/admin-api/admin/payment/update', {
        method: 'POST',
        data: data
    });
}

export async function approvePayment(data?: { [key: string]: any }) {
    return request('/admin-api/admin/payment/approve', {
        method: 'POST',
        data: data
    });
}

export async function discardPayment(data?: { [key: string]: any }) {
    return request('/admin-api/admin/payment/discard', {
        method: 'POST',
        data: data
    });
}

export async function pagedPayment(
    params: {
        current?: number;
        pageSize?: number;
    },
    options?: { [key: string]: any },
) {
    const intl = getIntl(); 
    try {
        const response = await request<API.ApiResponse>('/admin-api/admin/payment/page', {
            method: 'GET',
            params: {
                ...params,
            },
            ...(options || {}),
        });

        if (response?.code !== 0) {
            message.error(response?.msg  +  intl.formatMessage({ id: 'request.error.default' }) );
            return [];
        }

        return response?.data || [];
    } catch (error) {
        message.error(intl.formatMessage({ id: 'request.error.network' }) );
        return [];
    }
}